package cn.yunhe.servlet;

import cn.yunhe.bean.Comment;
import cn.yunhe.bean.User;
import cn.yunhe.biz.CommentService;
import cn.yunhe.util.DateUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
@WebServlet("/HotelCommentServlet")
public class HotelCommentServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        HttpSession session = req.getSession();
        User user = (User) session.getAttribute("user");
        String context =req.getParameter("context");
        String comtime = DateUtil.getNowTime();
        CommentService commentService =new CommentService();
        Comment comment= new Comment(context,comtime);
        int flag = commentService.insertHotelComment(comment);

        if(flag>0){
            req.getRequestDispatcher("HotelPriceServlet?id=${user.userId}").forward(req,resp);
        }
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }
}
